package com.ibeetl.cms.service;

import com.ibeetl.admin.core.service.BaseService;
import com.ibeetl.admin.core.util.PlatformException;
import com.ibeetl.cms.dao.RentingDao;
import com.ibeetl.cms.entity.Renting;
import com.ibeetl.cms.web.query.RentingQuery;
import org.beetl.sql.core.engine.PageQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Renting Service
 */

@Service
@Transactional
public class RentingService extends BaseService<Renting>{

    @Autowired
    private RentingDao rentingDao;

    public PageQuery<Renting> queryByCondition(PageQuery query){
        PageQuery ret =  rentingDao.queryByCondition(query);
        queryListAfter(ret.getList());
        return ret;
    }

    public void batchDelRenting(List<Long> ids){
        try {
            rentingDao.batchDelRentingByIds(ids);
        } catch (Exception e) {
            throw new PlatformException("批量删除Renting失败", e);
        }
    }

    public PageQuery<Renting> queryEmployees(PageQuery page) {
        page.setPageSize(Integer.MAX_VALUE);
        PageQuery ret =  rentingDao.queryEmployees(page);
        queryListAfter(ret.getList());
        return ret;
    }

    //查企业
    public PageQuery<Renting>findenterprise(PageQuery query){
        PageQuery ret =  rentingDao.findenterprise(query);
        queryListAfter(ret.getList());
        return ret;
    }

    public List<Renting>queryCompany(RentingQuery condtion){
        List<Renting> ret =  rentingDao.queryCompany(condtion);
        queryListAfter(ret);
        return ret;
    }

    public PageQuery<Renting> queryDoneTask(PageQuery page) {
        PageQuery ret =  rentingDao.queryDoneTask(page);
        queryListAfter(ret.getList());
        return ret;
    }

    public int  findMonth(Long user_id){
        return rentingDao.findMonth(user_id);
    }

    public int queryEmployeesCount(RentingQuery condition) {
        return rentingDao.queryEmployeesCount(condition);
    }
}